package main

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

// UserInfo 用户信息

type UserInfo struct {
	gorm.Model
	Name string `gorm:"name:"`
	Gender string  `gorm:"gender:"`
	Hobby string    `gorm:"hobby:"`
}


func main() {
	db, err := gorm.Open("mysql", "root:123456qwe@(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local")
	if err!= nil{
		panic(err)
	}
	defer db.Close()

	// 自动迁移
	//db.AutoMigrate(&UserInfo{})

	//u1 := UserInfo{Name:"陆杰",Gender: "男",Hobby: "篮球"}
	//u2 := UserInfo{Name:"林冲", Gender:"女", Hobby:"足球"}

	// 创建记录
	//每次增加的时候，会自动将没有补全的字段自动赋值
	//db.Create(&u1)
	//db.Create(&u2)

	var users=[]UserInfo{{Name:"hauzi"},{Hobby:"羽毛球"},{Name:"liujie"}}
	db.Create(&users)
	for _,u:=range users{
		fmt.Println(u.ID)
	}





}

